﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SiteWorx_WebParts_Basic_ContactUs_ContactUsEditor : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            LoadEditor();
    }

    private void LoadEditor()
    {
        string contactUsWPDataId = Request.QueryString["contactUsWPDataId"].ToString();

        if (Session[contactUsWPDataId] != null)
        {
            ContactUsWebPartData data = (ContactUsWebPartData)Session[contactUsWPDataId];

            txtEmailTo.Text = data.To;
            txtCC.Text = data.CC;
            txtBCC.Text = data.BCC;
        }
    }

    protected void btnFinish_Click(object sender, EventArgs e)
    {
        string contactUsWPDataId = Request.QueryString["contactUsWPDataId"].ToString();

        ((ContactUsWebPartData)Session[contactUsWPDataId]).To = txtEmailTo.Text;
        ((ContactUsWebPartData)Session[contactUsWPDataId]).CC = txtCC.Text;
        ((ContactUsWebPartData)Session[contactUsWPDataId]).BCC = txtBCC.Text;
       
        BuildUpdateScript(contactUsWPDataId);
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        string contactUsWPDataId = Request.QueryString["contactUsWPDataId"].ToString();
        BuildUpdateScript(contactUsWPDataId);
    }

    private void BuildUpdateScript(string contactUsWPDataId)
    {
        string functionName = "Update_" + contactUsWPDataId.Replace("-", "_");
        string script = "var wnd = getRadWindow(); wnd.BrowserWindow." + functionName + "(wnd); wnd.close();";

        ScriptManager.RegisterStartupScript(this, this.GetType(), "UpdateParentWebPart", script, true);
    }
}
